﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace _测试SqlHelper
{
    public class SqlUtil
    {
        public static string ConfigString = ConfigurationManager.ConnectionStrings["Default"].ToString();

        public static object ExecuteScalar(string connString, CommandType sqlType, string sqlText,
            params SqlParameter[] para)
        {
            object obj = null;
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandType = sqlType;
                    cmd.Connection = conn;
                    cmd.CommandText = sqlText;
                    cmd.Parameters.AddRange(para);
                    obj = cmd.ExecuteScalar();
                }
                conn.Close();
            }

            return obj;
        }
    }
}